﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoForSnake
{
    //蛇身体的每一单元,块
    public class Block
    {
        //是否为蛇头
        private bool _isHead;

        public bool IsHead
        {
            get { return _isHead; }
            set { _isHead = value; }
        }
        //蛇块的编号
        private int _blockNumber;

        public int BlockNumber
        {
            get { return _blockNumber; }
            set { _blockNumber = value; }
        }
        //蛇块的左上角位置
        private Point _origin;

        public Point Origin
        {
            get { return _origin; }
            set { _origin = value; }
        }

        //根据指定位置画蛇块
        public void ShowBlock(Graphics g)
        {
            Bitmap bitMap;
            if (IsHead)
            {
                //蛇头
                bitMap = new Bitmap(Image.FromFile("SnakeHead.png"));

            }
            else
            {
                bitMap = new Bitmap(Image.FromFile("GreenBody.png"));
            }
            Rectangle rec = new Rectangle(Origin.X, Origin.Y, 15, 15);
            g.DrawImage(bitMap, rec);
        }

        //消除蛇块
        public void UnShowBlock(Graphics g)
        {
            SolidBrush brush = new SolidBrush(Color.Silver);
            g.FillRectangle(brush, Origin.X, Origin.Y, 15, 15);
        }
    }
}
